import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import {resolve} from 'path'
// https://vitejs.dev/config/
export default defineConfig(({ command })=>{
  return {
    plugins: [vue()],
    base: command === 'build' ? '/ts' : '/',
    resolve: {
      alias: {
        '@': resolve(__dirname, './src'),
        assets: resolve(__dirname, './src/assets'),
      }
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: '@use "sass:math"; @use "./src/style/otherStyle.scss" as *;' // 全局公共样式
        }
      }
    },
    define:{
      "process.env": {
        mode:command,
        BASE_URL:command === 'build' ? '/' : '/',
      }
    },
    build: {
      outDir: 'ts',
    },
    server: {
      hmr: true,
      host: '0.0.0.0',
      port: 8080,
      proxy: {
        "/config-center": {
          target: "http://10.110.104.135/config-center/", // 测试
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/config-center/, '/')
        },
        "/simulation": {
          target: "http://10.110.104.135/simulation/", // 测试
          // target: "http://10.12.77.203/tzqxlk/", // 通州
          changeOrigin: true,
          ws: true,
          rewrite: (path) => path.replace(/^\/simulation/, '/')
        },
      }
    },
  }
})
